import {ITabe} from './type/index'

export interface State {
    count: number,
    collapse: boolean,
    tabsList: Array<ITabe>,
    userInfo: any,
    token: string
}

import {defineStore} from "pinia";

export const userStore = defineStore('main', {
    state: (): State => {
        return {
            count: 0,
            collapse: false,
            tabsList: [],
            userInfo: {},
            token: ''
        }
    } ,
    // 开启持久化
    persist: {
        enabled: true, // 启用
        strategies: [
            // storage 可选localStorage或sessionStorage
            // paths 给指定数据持久化
            { key: 'user', storage: localStorage, paths: ['token', 'userInfo'] }
        ]
    },

    getters: {
    },
    actions: {
        addTabe(tab: ITabe) {
            if (this.tabsList.some(item => item.path === tab.path)) return;
            this.tabsList.push(tab);
        },
        setToken(token: string) {
            this.token = token
        }
    }
})
